#include "mainwidget.h"
#include "ui_mainwidget.h"
#include <QtWidgets>
#include <QtGui>

MainWidget::MainWidget(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWidget)
{
    ui->setupUi(this);

    workspace = new QMdiArea;
    setCentralWidget(workspace);

    createMenu();

    QMainWindow *window1=new QMainWindow;
    window1->setWindowTitle(tr("Window 1"));
    QTextEdit *edit1=new QTextEdit;
    edit1->setText(tr("Window 1"));
    window1->setCentralWidget(edit1);

    QMainWindow *window2=new QMainWindow;
    window2->setWindowTitle(tr("Window 2"));
    QTextEdit *edit2=new QTextEdit;
    edit2->setText(tr("Window 2"));
    window2->setCentralWidget(edit2);

    QMainWindow *window3=new QMainWindow;
    window3->setWindowTitle(tr("Window 3"));
    QTextEdit *edit3=new QTextEdit;
    edit3->setText(tr("Window 3"));
    window3->setCentralWidget(edit3);

    workspace->addSubWindow(window1);
    workspace->addSubWindow(window2);
    workspace->addSubWindow(window3);
}

MainWidget::~MainWidget()
{
    delete ui;
}

void MainWidget::createMenu()
{

    QMenu *layoutMenu = menuBar()->addMenu(tr("Layout"));

    QAction *arrange = new QAction(tr("Arrange Icons"), this);
    connect(arrange, SIGNAL(triggered()), workspace, SLOT(arrangeIcons()));
    layoutMenu->addAction(arrange);

    QAction *title = new QAction(tr("title"), this);
    connect(title, SIGNAL(triggered()), workspace, SLOT(tileSubWindows()));
    layoutMenu->addAction(title);

    QAction *cascade = new QAction(tr("cascade"), this);
    connect(cascade, SIGNAL(triggered()), workspace, SLOT(cascadeSubWindows()));
    layoutMenu->addAction(cascade);

    QMenu *otherMenu = menuBar()->addMenu(tr("Other"));

    QAction *scrollAct = new QAction(tr("Scroll"), this);
    connect(scrollAct, SIGNAL(triggered()), this, SLOT(slotScroll()));
    otherMenu->addAction(scrollAct);
    otherMenu->addSeparator();

    QAction *nextAct = new QAction(tr("Next"), this);
    connect(nextAct, SIGNAL(triggered()), workspace, SLOT(activateNextSubWindow()));
    otherMenu->addAction(nextAct);

    QAction *previousAct = new QAction(tr("Previous"), this);
    connect(previousAct, SIGNAL(triggered()), workspace, SLOT(activatePreviousSubWindow()));
    otherMenu->addAction(previousAct);


}

void MainWidget::slotScroll()
{
   // workspace->setScrollBarsEnabled(!workspace->scrollBarsEnabled());
    //workspace->setOption(Qt::DontMaximizeSubWindowOnActivation);
}

